<template>
  <div class="order-confirm">
    <el-container>
      <el-main>
        <div class="address-section">
          <h3>收货地址</h3>
          <div v-for="(address, index) in addresses" :key="index" class="address-item">
            <el-radio v-model="selectedAddress" :label="address.id">{{ address.detail }}</el-radio>
          </div>
        </div>

        <div class="order-info">
          <h3>订单信息</h3>
          <div class="product-card">
            <img :src="currentProduct.homeImage" alt="商品图片" />
            <div class="product-details">
              <p>{{ currentProduct.title }}</p>
              <p>价格: ¥{{ currentProduct.price }}</p>
            </div>
          </div>
        </div>

        <div class="price-detail">
          <h3>价格明细</h3>
          <ul>
            <li>商品总价: ¥{{ currentProduct.price }}</li>
            <li>运费: ¥0.00</li>
            <li><strong>合计: ¥{{ currentProduct.price }}</strong></li>
          </ul>
          <el-button type="primary" @click="confirmPurchase">确认购买</el-button>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const selectedAddress = ref(null);
const addresses = [
  // 假设这里是从后端获取的地址数据
  {
    id: 1,
    detail: '河南省信阳市淮滨县第二高级中学乌龙大道淮滨县第二高级中学 张义 18211729685'
  },
  // 其他地址...
];

const currentProduct = ref({
  title: '健身房管理系统 | Java | SpringBoot | Vue | 前后',
  homeImage: 'https://placehold.co/300x300', // 使用占位图片
  price: 5.99
});

const confirmPurchase = () => {
  if (!selectedAddress.value) {
    alert('请选择收货地址');
    return;
  }
  // 这里可以添加实际的购买逻辑，例如调用后端接口进行购买操作
  alert('购买成功！');
  router.push('/'); // 购买成功后跳转到首页或其他页面
};
</script>

<style scoped>
.order-confirm {
  padding: 20px;
}

.address-section, .order-info, .price-detail {
  margin-bottom: 20px;
}

.address-item {
  margin-bottom: 10px;
}

.product-card {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.product-card img {
  width: 100px;
  height: 100px;
  object-fit: cover;
  margin-right: 20px;
}

.product-details p {
  margin: 5px 0;
}
</style>
